package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.ComboTypeEnum;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SerialNumberPoJo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.InstockTypeEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.PurchaseInstockEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;

/**
 * 采购入库单枚举
 *
 * @author feng.zheng
 * @date 2019/11/27 17:13
 */
@Getter
public enum TempPurchaseInstockEnum {
    //
    BASE_INFO(PurchaseInstockEnum.BASE_INFO),
    SHEET_NO(PurchaseInstockEnum.SHEET_NO),
    TIME(PurchaseInstockEnum.TIME),
    SUPPLIER_ID(PurchaseInstockEnum.SUPPLIER_ID),
    REF_ID(PurchaseInstockEnum.REF_ID),
    WAREHOUSE_ID(PurchaseInstockEnum.WAREHOUSE_ID),
    PRODUCT_INFO(PurchaseInstockEnum.PRODUCT_INFO),
    PRODUCT(PurchaseInstockEnum.PRODUCT),
    EXTEND_INFO(PurchaseInstockEnum.EXTEND_INFO),
    MANAGER_ID(PurchaseInstockEnum.MANAGER_ID),
    MEMO(PurchaseInstockEnum.MEMO),

    SYSTEM_INFO(PurchaseInstockEnum.SYSTEM_INFO),
    CREATOR_ID(PurchaseInstockEnum.CREATOR_ID),
    ADD_TIME(PurchaseInstockEnum.ADD_TIME),
    UPDATE_TIME(PurchaseInstockEnum.UPDATE_TIME),

    TYPE(PurchaseInstockEnum.TYPE),
    INCOMING(PurchaseInstockEnum.INCOMING),
    WAREHOUSE_ID_LINKED_TEXT(PurchaseInstockEnum.WAREHOUSE_ID_LINKED_TEXT),
    REF_ID_LINKED_TEXT(PurchaseInstockEnum.REF_ID_LINKED_TEXT),
    SUPPLIER_ID_LINKED_TEXT(PurchaseInstockEnum.SUPPLIER_ID_LINKED_TEXT),

    ;
    private PurchaseInstockEnum anEnum;

    TempPurchaseInstockEnum(PurchaseInstockEnum purchaseInstockEnum) {
        this.anEnum = purchaseInstockEnum;
    }
    public static List<TempPurchaseInstockEnum> getAllEnum() {
        List<TempPurchaseInstockEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }
    /**
     * 初始化编号
     *
     */
    public static void initSheetNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SHEET_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        // 不能重复
        fieldAttrEntity.setNoRepeat(1);
        // 默认的编号规则
        SerialNumberPoJo serialNumberPoJo = InitExplainsHelper.setSerialNumber(SerialNumberEnum.PURCHASE_INSTOCK_NO);
        fieldAttrEntity.setSerialNumber(serialNumberPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化关联供应商
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initSupplierId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setLinkedText(SUPPLIER_ID_LINKED_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);

        saasParticularAttributePoJo.setRelyType("base");
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelySubModel("supplier");

        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化日期
     *
     * @param fieldAttrEntity
     */
    public static void initTime(FieldAttrEntity fieldAttrEntity) {
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.TODAY.getAlias());
        fieldAttrEntity.setDateType(DateTimeEnum.TIME.getType());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }
    /**
     * 初始化关联客户
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initWarehouseId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setLinkedText(WAREHOUSE_ID_LINKED_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化入库类型
     *
     * @author chaoxiong.lei
     * @date  11:01 2019/1/18
     **/
    public static void initType(FieldAttrEntity fieldAttrEntity) {
        // 将出库类型设置为下拉选项
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(InstockTypeEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initRefId(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setLinkedText(REF_ID_LINKED_TEXT.anEnum.getAttr());
        fieldAttrEntity.setIsMultiBusiness(1);
        fieldAttrEntity.setBusinessType(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode());
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.PURCHASE.getCode());
        fieldAttrEntity.setIsForbidden(0);
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyAttr(SUPPLIER_ID.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 物流公司
     */
    public static void initExpressNo(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setComboType(ComboTypeEnum.CUSTOM.getType());
        fieldAttrEntity.setDictionaryFlag(0);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initManagerId(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setMultiple(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.WAREHOUSE_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.WAREHOUSE_MANAGER));
    }

    public static void initProducts(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setIsForbidden(0);
    }
}
